/**
 * Copyright (c) 2006, PORTALIER Julien
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * Inspired by Dombuilder, Copyright (c) 2006 Dan Webb
 * 
 * @package    Feather-CM
 * @subpackage Javascript
 * @copyright  Copyright (c) 2006, Julien PORTALIER
 * @link       http://portalier.com/feather
 * @license    http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

var DOM = new Class(
{
	/**
	 * new DOM(tag || element, [attributes], [child_1], [child_2], ...);
	 *
	 * Examples:
	 * 
	 * new DOM('div');
	 * new DOM('div', {'class': 'toto'});
	 * new DOM('div',
	 *   new DOM('p', 'this is a dummy text'),
	 *   new DOM('p', {'class': 'silly'}, 'this is a silly text')
	 * );
	 */
	initialize: function()
	{
		arguments.shift = [].shift;
		
		// params
		var tag = arguments.shift(), attributes;
		
		if (arguments.length > 0)
		{
			if ($type(arguments[0]) == 'object')
				attributes = arguments.shift();
		}
		
		// element
		var el = $(($type(tag) == 'string') ? document.createElement(tag) : tag);
		el.setProperties(attributes || {});
		
		// childs
		for (i = 0; i < arguments.length; i++)
		{
			switch($type(arguments[i]))
			{
				case 'string':
					el.appendChild(document.createTextNode(arguments[i]));
					break;
				case 'element':
					el.appendChild(arguments[i]);
			}
		}
		
		return el;
	}
});